package com.liveinstars.common.exception;

import com.alibaba.fastjson.JSON;
import com.liveinstars.common.enums.SystemExceptionEnum;
import com.google.common.collect.Maps;

import java.util.Map;

/**
 * @author ting
 * @version v1.0
 * @ClassName: SystemException
 * @Description: TODO
 * @date 2019-04-26
 */
public class SystemException extends RuntimeException {

    private int code;

    private String errorMsg;

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getErrorMsg() {
        return errorMsg;
    }

    public void setErrorMsg(String errorMsg) {
        this.errorMsg = errorMsg;
    }

    public SystemException(SystemExceptionEnum systemExceptionEnum) {
        this.code = systemExceptionEnum.getCode();
        this.errorMsg = systemExceptionEnum.getErrorMsg();
    }

    public String getMessageJSONString(){
        Map<String,String> map = Maps.newHashMap();
        map.put("code", String.valueOf(code));
        map.put("message", errorMsg);
        return JSON.toJSONString(map);
    }
}
